package hust.music.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import hust.music.action.base.ActionBase;
import hust.music.entity.User;
import hust.music.service.HomePageModService;

/**
 * AddDeleteFollowFriendAction
 * 
 * @author Txazo
 * @since 1.0
 */
@Controller
@Scope("session")
public class AddDeleteFollowFriendAction extends ActionBase {

	private static final long serialVersionUID = 1L;

	/** 是否当前用户标识 */
	private int flag;
	/** 是否删除好友标识 */
	private int isDelete;

	/** 关注标识 */
	private int isFollow;
	/** 好友标识 */
	private int isFriend;

	@Autowired
	private HomePageModService homePagePageModService;

	/**
	 * 关注好友初始化
	 * 
	 * @return 逻辑视图
	 */
	public String init() {
		User user = (User) session.get("user");
		User home = (User) session.get("home");

		if (user.getId() == home.getId()) {
			flag = 1;
		} else {
			flag = 0;
			isFollow = homePagePageModService.getIsFollow(user, home);
			isFriend = homePagePageModService.getIsFriend(user, home);
		}

		return "init";
	}

	/**
	 * 取消和添加关注
	 * 
	 * @return 逻辑视图
	 */
	public String follow() {
		User user = (User) session.get("user");
		User home = (User) session.get("home");
		isFollow = homePagePageModService.updateFollow(user, home);

		return "follow";
	}

	/**
	 * 删除和添加好友
	 * 
	 * @return 逻辑视图
	 */
	public String friend() {
		User user = (User) session.get("user");
		User home = (User) session.get("home");
		isFriend = homePagePageModService.updateFriend(user, home, isDelete);

		return "friend";
	}

	public int getIsFollow() {
		return isFollow;
	}

	public void setIsFollow(int isFollow) {
		this.isFollow = isFollow;
	}

	public int getIsFriend() {
		return isFriend;
	}

	public void setIsFriend(int isFriend) {
		this.isFriend = isFriend;
	}

	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

	public int getIsDelete() {
		return isDelete;
	}

	public void setIsDelete(int isDelete) {
		this.isDelete = isDelete;
	}

}
